<?php

namespace Modules\Auth\Http\Controllers;



use Illuminate\Contracts\Support\Renderable;
use Illuminate\Support\Facades\Hash;
use Modules\Auth\Entities\User;
use Modules\Auth\Http\Requests\UserRequest;
use Modules\Auth\Services\UserService;
use Modules\Common\Http\Controllers\CommonController;

class UserController extends CommonController
{
    private $service;
    public function __construct(UserService $service)
    {
        $this->service = $service;
    }

    public function login(UserRequest $request){
        $result = $this->service->login($request->all());
        return $this->success($result);
    }

    public  function register(UserRequest $request){
        if ($request->filled('password')) {
            $request->offsetSet('password1', $request->password);
            $request->offsetSet('password', Hash::make($request->password));
        }
        $result = $this->service->register($request->all());
        return $this->created($result);
    }
    public  function logout(){
        dd("推出登录");
    }
    public function refreshToken(){
        dd("刷新令牌");
    }
    /**
     * Remove the specified resource from storage.
     * @param int $id
     * @return Renderable
     */
    public function destroy($id)
    {
       User::destroy($id);
       return $this->noContent();
    }

}
